package com.mowanka.mokeng.data.model.bean

import android.graphics.Color
import androidx.annotation.DrawableRes
import com.mowanka.mokeng.R
import com.mowanka.mokeng.app.ext.removeZero
import com.mowanka.mokeng.data.model.enums.ProductType
import me.hgj.jetpackmvvm.base.appContext

data class CommentProduct(
    val id: String,
    val content: String,
    val coverPic: String,
    val coverWidth: Int,
    val coverHeight: Int,
    val price: String,
    val labelList: MutableList<MKLabel>? = null,
    val pricePre: String? = null,
    val pricePost: String? = null,
    val extra: String? = null,
    val sellout: Boolean = false,
    val type: Int = 0,
    val protoId: String? = null,
    val stateStr: String? = null,
    val endTime: String? = null,
    var isSelect: Boolean = false,
    val secondHand: Boolean = false,
    val isNew: Boolean = false,
    val isDsl: Boolean = false
)


fun ArrayList<ProductResponse>.format(): ArrayList<CommentProduct> {
    return arrayListOf<CommentProduct>().let { list->
        forEach {
            list.add(
                CommentProduct(
                    it.id,
                    it.name,
                    it.coverPic,
                    it.coverWidth,
                    it.coverHeight,
                    it.presentPrice.toString().removeZero(),
                    mutableListOf<MKLabel>().apply {
                        if (it.type == ProductType.Spot && it.isMokengHouse == 1) add(SPOT)
                        if (it.type == ProductType.Spot && it.isMokengHouse == 0) add(SECONDHAND)
                        if (it.floatType == 1) add(
                            MKLabel(
                                R.drawable.shape_c_eeeeee_2,
                                "涨¥${it.floatPrice.toString().removeZero()}",
                                appContext.resources.getColor(R.color.custom_red)
                            )
                        )
                        if (it.floatType == 2) add(
                            MKLabel(
                                R.drawable.shape_c_eeeeee_2,
                                "省¥${it.floatPrice.toString().removeZero()}",
                                appContext.resources.getColor(R.color.custom_green)
                            )
                        )
                    },
                    extra = it.skuProperties,
                    sellout = it.totalStock == 0,
                    type = ACTION_PRODUCT,
                    secondHand = it.type == ProductType.Spot && it.isMokengHouse == 0
                )
            )
        }
        list
    }
}

private const val ACTION_PROTO = 0
private const val ACTION_AUCTION = 1
private const val ACTION_LUCK = 2
private const val ACTION_PRODUCT = 3
private const val ACTION_BUYDEMAND = 4
private const val ACTION_CARD = 5
private const val ACTION_TREE = 6

data class MKLabel(@DrawableRes var res: Int, val label: String, val textColor: Int = Color.parseColor("#FFFFFF"))

private val RESERVE by lazy { MKLabel(R.drawable.shape_c_1bc088_2, "预留") }
private val PRESELL by lazy { MKLabel(R.drawable.shape_c_dd1a1a_2, "预售") }
private val TRANSFER by lazy { MKLabel(R.drawable.shape_c_dd1a1a_2, "官转") }
private val SPOT by lazy { MKLabel(R.drawable.shape_c_000000_2, "现货") }
private val AUTH by lazy { MKLabel(R.drawable.shape_c_000000_2, "认证") }
private val AUCTION by lazy { MKLabel(R.drawable.shape_c_000000_2, "拍卖") }
private val BLINDBOX by lazy { MKLabel(R.drawable.shape_c_f3c974_2, "抽", Color.parseColor("#000000")) }
private val VIP by lazy { MKLabel(R.drawable.shape_c_f1cc8a_2, "黑卡", Color.parseColor("#000000")) }
private val BOUNTY by lazy { MKLabel(R.drawable.shape_c_000000_2, "一番赏") }
private val SECONDHAND by lazy { MKLabel(R.drawable.shape_c_eeeeee_2, "二手", Color.parseColor("#333333")) }
private val DEPOSIT by lazy { MKLabel(R.drawable.shape_c_000000_2, "现货") } //模坑仓库 -> 现货
private val SOLDOUT by lazy { MKLabel(R.drawable.shape_c_f2f2f2_2, "无货", Color.parseColor("#979797")) }
private val BUYDEMANDTRANS by lazy { MKLabel(R.drawable.shape_c_dd1a1a_2, "求购官转") }
private val BUYDEMANDSPOT by lazy { MKLabel(R.drawable.shape_c_000000_2, "求购现货") }
private val MOLI by lazy { MKLabel(R.drawable.shape_c_0d84fe_2, "模坑赏") }
private val TREE by lazy { MKLabel(R.drawable.shape_c_0d84fe_2, "占地寻宝") }